package com.itheima.mobilesafe.viruskilling;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itheima.mobilesafe.R;
import com.itheima.mobilesafe.viruskilling.adapter.MyNetScanVirusAdapter;

public class NetVirusCheckActivity extends AppCompatActivity implements View.OnClickListener{


    /*该activity用于将病毒以条目的信息显示*/
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_net_virus_check);
        Intent intent = getIntent();
        String[] virus_infos = intent.getStringArrayExtra("virus_info");
        initview(virus_infos);


        //startConnectCheckVirus(virus_infos);
    }


    //开启俺的adapter
    private void initview(String [] virus_infos) {
        //设置蓝色背景
        RelativeLayout title_bar = findViewById(R.id.title_bar);
        title_bar.setBackgroundColor(getResources().getColor(R.color. blue_color));
        TextView tv_back = findViewById(R.id.tv_back);//获取返回键
        tv_back.setOnClickListener(this);//设置返回键的点击事件的监听器
        ((TextView) findViewById(R.id.tv_main_title)).setText("联网病毒扫描");//设置界面标题
        tv_back.setVisibility(View.VISIBLE);//显示返回键
        /*listview取数据*/
        ListView lv = findViewById(R.id.gzz_listview);
        final MyNetScanVirusAdapter myNetScanVirusAdapter = new MyNetScanVirusAdapter(this,virus_infos);
        lv.setAdapter(myNetScanVirusAdapter);
        //为listview每个条目添加点击事件
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                //System.out.println("itemID:"+myNetScanVirusAdapter.getItemId(position));
                String choseMD5 = (String) myNetScanVirusAdapter.getItem(position);
                Intent intent = new Intent(NetVirusCheckActivity.this,NetVirusInformationActivity.class);
                intent.putExtra("chose_md5",choseMD5);
                startActivity(intent);
            }
        });
    }



    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_back: //返回键点击事件
                finish();
                break;
        }
    }




    //获取到组件对象
   /* private void initview() {
        mywebview = findViewById(R.id.mywebview);
        mywebview.getSettings().setJavaScriptEnabled(true);
        mywebview.setWebViewClient(new WebViewClient());
    }*/


   /* private void startConnectCheckVirus(String [] viruses) {
        Intent intent = new Intent();
        for(String s:viruses){
            mywebview.loadUrl("https://habo.qq.com/file/showdetail?md5=" + s);
        }
    }
*/

}
